


<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

    <title>Using Gurobi with CVX &#8212; CVX Users&#39; Guide</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="_static/cloud.css" />
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noticia+Text:400,i,b,bi|Open+Sans:400,i,b,bi|Roboto+Mono:400,i,b,bi&amp;display=swap" type="text/css" />
    
    <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
    <script src="_static/jquery.js"></script>
    <script src="_static/underscore.js"></script>
    <script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="_static/doctools.js"></script>

    
    
     
        <script src="_static/jquery.cookie.js"></script>
    

    
     
        <script src="_static/cloud.base.js"></script>
    

    
     
        <script src="_static/cloud.js"></script>
    

    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Using MOSEK with CVX" href="mosek.html" />
    <link rel="prev" title="Credits and Acknowledgements" href="credits.html" /> 
        <meta name="viewport" content="width=device-width, initial-scale=1">
  </head><body>
    <div class="relbar-top">
        
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mosek.html" title="Using MOSEK with CVX"
             accesskey="N">next</a> &nbsp; &nbsp;</li>
        <li class="right" >
          <a href="credits.html" title="Credits and Acknowledgements"
             accesskey="P">previous</a> &nbsp; &nbsp;</li>
    <li><a href="index.html">CVX Users&#39; Guide</a> &#187;</li>

        <li class="nav-item nav-item-this"><a href="">Using Gurobi with CVX</a></li> 
      </ul>
    </div>
    </div>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="using-gurobi-with-cvx">
<span id="gurobi"></span><h1>Using Gurobi with CVX<a class="headerlink" href="#using-gurobi-with-cvx" title="Permalink to this heading">¶</a></h1>
<section id="about-gurobi">
<h2>About Gurobi<a class="headerlink" href="#about-gurobi" title="Permalink to this heading">¶</a></h2>
<p><a class="reference external" href="http://www.gurobi.com">Gurobi Optimization</a> was founded in 2008 by some of the most
experienced and respected members of the optimization community. The Gurobi solver quickly
became an industry performance leader in linear, quadratic, and mixed-integer programming.
Gurobi is a fantastic solver for use with CVX, particularly with the integer and binary
variable capability added in CVX 2.0.</p>
<p>Using Gurobi with CVX requires a valid license:</p>
<ul>
<li><p><em>Academic users</em>: information about obtaining a license can be found on the
<a class="reference external" href="https://www.gurobi.com/academia/academic-program-and-licenses/">Gurobi Academic Program</a> page.</p></li>
<li><p><em>Commercial users</em> must purchase one of our CVX Professional licenses:</p>
<ul class="simple">
<li><p>A <em>bundled CVX + Gurobi license</em> allows Gurobi to be used exclusively within
CVX. This is the most cost-effective approach for users who do not intend
to use Gurobi outside of CVX and/or MATLAB.</p></li>
<li><p>A <em>bring-your-own-solver (BYOS)</em> license allows CVX to be paired with a
separate Gurobi license, enabling the same installation to be used within
CVX and separate from it.</p></li>
</ul>
<p>Please contact <a class="reference external" href="mailto:sales&#37;&#52;&#48;cvxr&#46;com">CVX Sales</a> for more information about either option, and
<a class="reference external" href="mailto:sales&#37;&#52;&#48;gurobi&#46;com">Gurobi Sales</a> for pricing information for standalone Gurobi licenses.</p>
</li>
</ul>
</section>
<section id="gurobilic">
<span id="id1"></span><h2>Using Gurobi with CVX<a class="headerlink" href="#gurobilic" title="Permalink to this heading">¶</a></h2>
<ol class="arabic">
<li><p>Download the the appropriate CVX bundle from the <a class="reference external" href="http://cvxr.com/cvx/download">CVX download page</a>
and following the regular installation instructions at <a class="reference internal" href="install.html#install"><span class="std std-ref">Installation</span></a>.
The standard bundles include a CVX-specific version of the Gurobi version 9.0.</p></li>
<li><p>Obtain the licenses for Gurobi and/or CVX, as needed:</p>
<ul class="simple">
<li><p>A Gurobi license code, which is composed of 32 hexidecimal digits in the format
<code class="docutils literal notranslate"><span class="pre">xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</span></code>. If you purchase a commercial CVX+Gurobi
package, you will receive this code in an email from CVX Research. If you are an
academic user, you will receive it directly from the <a class="reference external" href="https://www.gurobi.com/downloads/end-user-license-agreement-academic/">Gurobi academic license request</a> page.</p></li>
<li><p>A CVX license should be saved in a convenient location for Step 4. You
will need to be able to supply its full path to the <code class="docutils literal notranslate"><span class="pre">cvx_setup</span></code> command.</p></li>
</ul>
</li>
<li><p>If you need a full installation of Gurobi—because you wish to use a
different version than is bundled with CVX, or because you wish to use Gurobi
outside of CVX—obtain an appropriate installer from the <a class="reference external" href="https://www.gurobi.com/downloads/">Gurobi Download Center</a>
and follow their instructions. Confirm that it can be successfully run from
the MATLAB command line <em>before</em> proceeding with Step 2.</p></li>
<li><p>Next, retrieve your Gurobi license key by running the command <code class="docutils literal notranslate"><span class="pre">cvx_grbgetkey</span></code>
<em>{code}</em>, where <em>{code}</em> is the 32-digit Gurobi key. This is a convenience
wrapper around Gurobi’s own <code class="docutils literal notranslate"><span class="pre">grbgetkey</span></code> script. The command will look
something like this:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cvx_grbgetkey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
</pre></div>
</div>
<p><em>Important note for academic users:</em> this step must be run from a computer
connected to your university network (a VPN is usually sufficient).
Please consult the Gurobi documentation for more details.</p>
</li>
<li><p>Re-run <code class="docutils literal notranslate"><span class="pre">cvx_setup</span></code> so that the new Gurobi and/or CVX licenses can be detected.
If a CVX Professional license was obtained, supply the path to this file as the
argument to the <code class="docutils literal notranslate"><span class="pre">cvx_setup</span></code> command, as discussed in <a class="reference internal" href="install.html#licinstall"><span class="std std-ref">Installing a CVX Professional license</span></a>.</p></li>
</ol>
<p>If successful, the output of step 4 should show that Gurobi is among the list
of available solvers. If you installed both a standalone Gurobi bundled version of Gurobi,
they should both be available after setup.</p>
</section>
<section id="selecting-gurobi-as-your-default-solver">
<h2>Selecting Gurobi as your default solver<a class="headerlink" href="#selecting-gurobi-as-your-default-solver" title="Permalink to this heading">¶</a></h2>
<p>Even if Gurobi is successfully added to your solver list, it will not automatically
be selected as your default solver. To change this, type the following two commands
on the MATLAB command line:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cvx_solver gurobi
cvx_save_prefs
</pre></div>
</div>
<p>The first command changes the active solver to Gurobi, but only for the current session.
The second line saves that change to CVX’s preference file, so that Gurobi will be
selected as the active solver every time you start MATLAB.</p>
<p>If multiple versions of Gurobi were found on the MATLAB path, then CVX will append a
numeral to the end of the solver name, allowing you to switch between them; e.g.,</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cvx_solver gurobi
cvx_solver gurobi_2
cvx_solver gurobi_3
</pre></div>
</div>
<p>and so forth.</p>
</section>
<section id="obtaining-support-for-cvx-and-gurobi">
<h2>Obtaining support for CVX and Gurobi<a class="headerlink" href="#obtaining-support-for-cvx-and-gurobi" title="Permalink to this heading">¶</a></h2>
<p>If you encounter problems using CVX and Gurobi, please contact
<a class="reference external" href="http://support.cvxr.com/">CVX Support</a> first instead of Gurobi.
If we can reproduce your problem, we will determine whether or not it is an
issue that is unique to CVX or needs to be forwarded to Gurobi for further
analysis.</p>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
        <p class="logo"><a href="index.html" title="index">
          <img class="logo" src="_static/cvxrlogo.png" alt="Logo"/>
        </a></p><div class="sphinx-toc sphinxlocaltoc">
    <h3><a href="index.html">Page contents</a></h3>
    <ul>
<li><a class="reference internal" href="#">Using Gurobi with CVX</a><ul>
<li><a class="reference internal" href="#about-gurobi">About Gurobi</a></li>
<li><a class="reference internal" href="#gurobilic">Using Gurobi with CVX</a></li>
<li><a class="reference internal" href="#selecting-gurobi-as-your-default-solver">Selecting Gurobi as your default solver</a></li>
<li><a class="reference internal" href="#obtaining-support-for-cvx-and-gurobi">Obtaining support for CVX and Gurobi</a></li>
</ul>
</li>
</ul>

  </div>
  <div class="sphinxprev">
    <h4>Previous page</h4>
    <p class="topless"><a href="credits.html"
                          title="Previous page">&larr; Credits and Acknowledgements</a></p>
  </div>
  <div class="sphinxnext">
    <h4>Next page</h4>
    <p class="topless"><a href="mosek.html"
                          title="Next page">&rarr; Using MOSEK with CVX</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/gurobi.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div><h3>Other links</h3>
<ul class="this-page-menu">
<li><a href="CVX.pdf" target="_blank">Download the PDF</a></li>
<li><a href="http://cvxr.com/cvx">CVX home page</a></li>
</ul>


<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
    
    
        <div class="sidebar-toggle-group no-js">
            
            <button class="sidebar-toggle" id="sidebar-hide" title="Hide the sidebar menu">
                 «
                <span class="show-for-small">hide menu</span>
                
            </button>
            <button class="sidebar-toggle" id="sidebar-show" title="Show the sidebar menu">
                
                <span class="show-for-small">menu</span>
                <span class="hide-for-small">sidebar</span>
                 »
            </button>
        </div>
    
      <div class="clearer"></div>
    </div>
    <div class="relbar-bottom">
        
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="mosek.html" title="Using MOSEK with CVX"
             >next</a> &nbsp; &nbsp;</li>
        <li class="right" >
          <a href="credits.html" title="Credits and Acknowledgements"
             >previous</a> &nbsp; &nbsp;</li>
    <li><a href="index.html">CVX Users&#39; Guide</a> &#187;</li>

        <li class="nav-item nav-item-this"><a href="">Using Gurobi with CVX</a></li> 
      </ul>
    </div>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright © 2012, CVX Research, Inc..
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.0.2.
    </div>
    <!-- cloud_sptheme 1.4 -->
  </body>
</html>